#include <iostream>
using namespace std;

struct date{
	int year,month,day;
	date(){
	}
	date(int y,int m,int d):year(y),month(m),day(d){
	}
	bool operator <= (const date &a){
		if( this->year<a.year || (this->year==a.year &&this->month<a.month) || 
		(this->year==a.year &&this->month==a.month &&this->day<=a.day) ) return true;
		else return false;
	}
};
int main(){
	freopen("in.txt","r",stdin);
	int n;
	string name,maxname,minname;
	date d;
	cin>>n;
	int cnt = 0;
	date max = date(2014,9,6),min = date(1814,9,6);
	while( n-- ){
		cin>> name;
		scanf("%d/%d/%d",&d.year,&d.month,&d.day);
//		cin>>name>>d.year>>d.month>>d.day;
//		cout<<d.year<<" "<<d.month<<" "<<d.day<<endl;
		if( date(1814,9,6)<=d&&d<=date(2014,9,6) ){
			++cnt;
			if( d<=max ){
				max = d;
				maxname = name;	
			}  
			if( min<=d ) {
				min = d;
				minname = name;	
			}
		} 
	}
	if( cnt==0 ) cout<<0;
	else cout<<cnt<<" "<<maxname<<" "<<minname;
	return 0;
}
